//
//  RecomomendModel.swift
//  FM
//
//  Created by x on 2017/8/23.
//  Copyright © 2017年 HLB. All rights reserved.
//

import UIKit

class RecomomendModel: NSObject {
    
    /// id
    var id:String?
    
    /// <#Description#>
    var sort:String?
    
    /// 类型
    var type:String?
    
    /// 显示图片
    var cover:String? {
        didSet {
            coverImageURL = URL(string: cover!)
        }
    }
    
    /// 内容标题
    var title:String?
    
    /// 跳转的URL地址
    var value:String? {
        didSet {
            if value!.hasPrefix("http") {
                self.jumpURL = URL(string: value!)
            }
        }
    }
    
    /// 图片的URL
    var coverImageURL:URL?
    
    /// 点击图片跳转的URL
    var jumpURL:URL?
    
    /// 快速返回一个数据模型数组
    ///
    /// - Parameter JSON: <#JSON description#>
    /// - Returns: <#return value description#>
    class func analysisData(data:AnyObject?) ->[RecomomendModel] {
        
        let recommends = data?["tuijian"] as![[String:AnyObject]]
        var models:[RecomomendModel] = [RecomomendModel]()
        for dic in recommends {
            let model = RecomomendModel(dic: dic)
            models.append(model)
        }
        
        return models
    }
    
    init(dic:[String: AnyObject]) {
        super.init()
        setValuesForKeys(dic)
    }
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
        print("key=====",key)
    }
    
    //重写descripation方法
    let tt = ["id","sort","type","cover","title","value"]
    override var description: String {
        let dic = dictionaryWithValues(forKeys: tt)
        
        return "\(dic)"
    }
}
